package main

import (
	"log"

	"gitee.com/z1gotool/z1crypto"
)

func main() {
	log.Println(`--------------- go research ---------------`)

	msg := "hellow word!"
	aesSecretKey := "my32digitkey12345678901234567890"

	// https://www.yii666.com/blog/129530.html
	// openssl genrsa -out private.pem 1024 //密钥长度，1024觉得不够安全的话可以用2048，但是代价也相应增大
	// openssl rsa -in private.pem -pubout -out public.pem //这样便生产了密钥。
	publicKey := `
		-----BEGIN PUBLIC KEY-----
		MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3oSDe9Gu6AcoNU0NYQRBi3Pid
		wqlet/PpMddqlqnUO4sP4R0/ABOHbf/1byVbfKsbpEQqan2+v8x7MvrjZtzl6cAq
		rGkp3zmfvMHSkYBaQFZym0Hc49sMCbygCy77Hw9PnXsFIFayTsT97Whd6U8HzKg5
		1wHoSW+eq2QmjZUCsQIDAQAB
		-----END PUBLIC KEY-----	
	`
	privateKey := `
		-----BEGIN RSA PRIVATE KEY-----
		MIICXwIBAAKBgQC3oSDe9Gu6AcoNU0NYQRBi3Pidwqlet/PpMddqlqnUO4sP4R0/
		ABOHbf/1byVbfKsbpEQqan2+v8x7MvrjZtzl6cAqrGkp3zmfvMHSkYBaQFZym0Hc
		49sMCbygCy77Hw9PnXsFIFayTsT97Whd6U8HzKg51wHoSW+eq2QmjZUCsQIDAQAB
		AoGBAIHnyFRR/5/gQit5GuxlYw09m9gnbSBn7HKtYuKx4UUWNoOuUr1N9YLai7f6
		wCffo0DzzZFgMsLt9t+1Kg4Tp/L/Z9n1zOIDTViETZrLChzpbaIf413d0kd7uwJd
		R4L5+adKWI7KNfHiuiJOycz7njhqQGVr30U2GNRRsL0YBhhRAkEA5BIbi10bpRnC
		ZCCM+sABXJPnoGwpJHZ5Q+Ntqsq5NbgBmQPZYisK5jgGUuDR1vuMkFnwve7IqEc1
		So9yiYQLnQJBAM4dz0SGRzhu0GkzIvbwXRxakTjQAVH2z/mF1JnRQkMelymkwb7A
		c1/N4/gWbphAoVwjnbc19YqhG2HUePPBGSUCQQDeL53R6UUTVMMCFIwDhKZO8HBI
		4tY6BYkh0CB4sMI6SSaVUSCn+FLH8XCHsSn8jFdmEZjtEAE/nw+VsaXdvlwpAkEA
		wWd5UExLUemxR7VDDsFWLT/SWqPbSUS1u+ZXKooPihmPL/U4EzxURkZUrjqmRdkH
		UATffcV1BELOBcswP1EmvQJBALpQG6QqeFzeCjFer1LyNDyhENeceyDsJ32T9X6y
		ZsfY0Y4XYNzLWsLGNsG5DT8p958wBytqZ/cnk2Kzes8RREQ=
		-----END RSA PRIVATE KEY-----
	`

	if `aes` != `` {
		log.Println(`-------aes,start-----`)
		encode, err := z1crypto.AesEncrypt(msg, aesSecretKey)
		log.Println(encode, err)
		log.Println(z1crypto.AesDecrypt(encode, aesSecretKey))
		log.Println(`-------aes,end-----`)
	}

	if `rsa` != `` {
		log.Println(`-------rsa,start-----`)

		encode, err := z1crypto.RsaEncrypt(msg, publicKey)
		log.Println(encode, err)

		decode, err := z1crypto.RsaDecrypt(encode, privateKey)
		log.Println(decode, err)

		log.Println(`-------rsa,end-----`)
	}

	if `base64` != `` {
		log.Println(`-------base64,start-----`)
		log.Println(z1crypto.Base64Encode(msg))
		log.Println(z1crypto.Base64Decode(z1crypto.Base64Encode(msg)))
		log.Println(z1crypto.Base64Encode(msg, true))
		log.Println(z1crypto.Base64Decode(z1crypto.Base64Encode(msg, true), true))
		log.Println(`-------base64,end-----`)
	}

	if `md5` != `` {
		log.Println(`-------md5,start-----`)
		log.Println(z1crypto.Md5(msg))
		log.Println(`-------md5,end-----`)
	}
}
